package com.atguigu.gmall.payment.demo;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;

/**
 * @author 李旭
 * @date 2021/12/4 15:33
 * @Description: 支付宝 接口测试
 */
public class AlipayDemo {


    //   统一收单下单并支付页面接口
    public static void main(String[] args) throws Exception{
        //公共参数
        AlipayClient alipayClient = new DefaultAlipayClient(
                "https://openapi.alipaydev.com/gateway.do",//沙箱地址
                "2016102100732915",//沙箱的帐户
                "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXLM2g8VS7Ax9XuSXYMV8qwEjiun8IX0QUPIxOnFm5sXEG3c9T3t6n3qJFHEGQ6BT6o+dsS77FJY3SIwWxzhw9KP7uB7PaLeGRisMMcsajHXM2Ci35vL0zPRZb3sWNfWum+wipkrEvzv+rXE/LXMCpDi1RAJTAsad6epjkWcraq6ucLaxiskUrX+SVrWQIzJsCWoNXFlW7YxYaxTXe+sKDxIyK4MlJs4YUoBiCozBR1r9wI9ZnNxDYzFPMwGOM/juxzXTJli/Zrb8UW94ub8L59d/Aq1rw8hWBi/ismL3P/aGxRvhpty4i6PCq4Z6rOXeP9leT50O6aGJVsAAjY9/ZAgMBAAECggEAS0SdZQKDQ1F8q3qdoxSB45E1ON3OHecAyGqVGRazfcchFWAeuA2BImewt2QoKPPEbj5pHPxhkVrvT67sSOjsGm9s7iqbm4e4hXRnRK1oxRIGqONMnMkiEn7ZwQgbqCTIEq1uVK+a1MjldvZRLFmT+xf57Biz93T8g/jCYv9qBpEl0CD/eICV/wQrNsjzNTfaeNt1fu9Xzyo0V7NLXN9u5H3Y6uhKBGYOdcnCr2cVL5tWIvHMKdrWSAWSu/FyJ7yAsBMPJG4m/f7kle2uYBFH76xDFzP8lCw6E2l/zJj4zp7cJAb2LM/HCsglbr/x/o9wghvMRJONEYVSfPqn7b2jYQKBgQD2Z/htaDGK/cG4hvSm2TsdIsHGd/PwWOSn/SsZW6YHb+dW15QorRvMBWzLdmCkrtrcPNON8mfDha4o7CbwlIN+kn5Pyi2ITiPlN1nIVS28DhfknRcpq5jUYgvKURj+AZ3LpUnXYCRlMxAkPwEPL/6SI4ZF7QGw99X0AXrS0ggKlQKBgQCdD6AvElpTyARNtRfHqofwMW0ZHcxHDMX8PwbfpV/Xhq+Fn/VcrfpSpANMWS3wPhILmk91WehL//jRGMWmbZeve3L9NYhq8ehysCEqwEvNdABaq6S7ihnELYQkNFwCdw5cr18SOg8nUHqacDJ2SxAZJRqMss7G5KJff52wLaYzNQKBgQCk9w6XEL66cxES3SdF3QF6jB53JS+npZvP6+rC21zYdc7HkSSb5ulJOgiQXvxsxLO55u8rhTJ68DCdLR0UzBkM0D7IZG7/ZnEZsGjnej9YO4c7gwBS4ZM7/TgvhwPYanSeNlatXqx/JCSWX6fx5wvkAuyOPBJ5zDLtXWBBbGP90QKBgCdEXdcG7qBdtH29Fensf7oUkWMjKQxmbCVpmI1XqkOXP9DXsh9uu9Pnf4+aCDs1OYu/E7iSNtqxb4LPf7LhWXgdFB2sQaQDQQtTb6dhllISe3gvy6q7lz+N5airkolnPKb9jXZgH6PDojN0c5lRoP+4YA/nMH1XciUQIduHPjM1AoGAODMkf/5b3bG8iu0f+ky3RbQ8n4/LPx39HH/pOZhAlu7opNO+YYLaajHJ+J+CX9wV/0NNIG6JwCXTriRaOj0DGMw+VtJ8Rh2MRAzd80SAjqroD3b7NbH4vJ5Thlcn0GRdGiQRF0W1757r+636mn5LsD+vncWaqv06dWBvkiRP0hY=",//沙箱的密钥
                "json",
                "UTF-8",
                "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv4FgjWsfvbXEkzs5T+z5r4X9m5Qh8OA0zlZA3T9yeCqlcRRqydMBfRsB4V9aHUH0KCV875mzF7Feh3VoDilcDpGtuKo5l7YRVnGSyQTq0pQjMFYi/wKGFGHAA37Wl2L/AMaGpT6CJncSqcAJssY61qmz/o9lw+hRq6KBfdktl4xm0d5f+uMgCLKqa6bYbFyG7vNZszGJ6yW2n6fFbZ0B4PgPXfrRFVG+OS204bi7sGDba6DuJPPuk8B/gkVoDkmKHNRnLXZi74jyZROlEXKr8JElZqpT6RODkKAmIRCGlQrAadUntgmymguRlN2K+TfSNIigY1FRekb/BudYhlbA5QIDAQAB",//支付宝公司的公钥
                "RSA2");//加密方式

        //请求参数
        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
        request.setNotifyUrl("");//异步回调
        request.setReturnUrl("");//同步回调
        JSONObject bizContent = new JSONObject();
        bizContent.put("out_trade_no", "20210817010101004");//atguigu1638321708734999
        bizContent.put("total_amount", 0.01);
        bizContent.put("subject", "测试商品");
        bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY");
        //bizContent.put("time_expire", "2022-08-01 22:00:00");

        //// 商品明细信息，按需传入
        //JSONArray goodsDetail = new JSONArray();
        //JSONObject goods1 = new JSONObject();
        //goods1.put("goods_id", "goodsNo1");
        //goods1.put("goods_name", "子商品1");
        //goods1.put("quantity", 1);
        //goods1.put("price", 0.01);
        //goodsDetail.add(goods1);
        //bizContent.put("goods_detail", goodsDetail);

        //// 扩展信息，按需传入
        //JSONObject extendParams = new JSONObject();
        //extendParams.put("sys_service_provider_id", "2088511833207846");
        //bizContent.put("extend_params", extendParams);

        request.setBizContent(bizContent.toString());
        AlipayTradePagePayResponse response = alipayClient.pageExecute(request);
        if (response.isSuccess()) {
            System.out.println(response.getBody());
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }


    }

    /**
     * // 响应为表单格式，可嵌入页面，具体以返回的结果为准
     * <form name="submit_form" method="post"
     *             action="https://openapi.alipay.com/gateway.do?charset=UTF-8&method=alipay.trade.page.pay&sign=k0w1DePFqNMQWyGBwOaEsZEJuaIEQufjoPLtwYBYgiX%2FRSkBFY38VuhrNumXpoPY9KgLKtm4nwWz4DEQpGXOOLaqRZg4nDOGOyCmwHmVSV5qWKDgWMiW%2BLC2f9Buil%2BEUdE8CFnWhM8uWBZLGUiCrAJA14hTjVt4BiEyiPrtrMZu0o6%2FXsBu%2Fi6y4xPR%2BvJ3KWU8gQe82dIQbowLYVBuebUMc79Iavr7XlhQEFf%2F7WQcWgdmo2pnF4tu0CieUS7Jb0FfCwV%2F8UyrqFXzmCzCdI2P5FlMIMJ4zQp%2BTBYsoTVK6tg12stpJQGa2u3%2BzZy1r0KNzxcGLHL%2BwWRTx%2FCU%2Fg%3D%3D&notify_url=http%3A%2F%2F114.55.81.185%2Fopendevtools%2Fnotify%2Fdo%2Fbf70dcb4-13c9-4458-a547-3a5a1e8ead04&version=1.0&app_id=2014100900013222&sign_type=RSA&timestamp=2021-02-02+14%3A11%3A40&alipay_sdk=alipay-sdk-java-dynamicVersionNo&format=json">
     * <input type="submit" value="提交" style="display:none" >
     * </form>
     * <script>document.forms[0].submit();</script>
     *
     *
     */
    /**
     * 10:25:06.317 [main] DEBUG sdk.biz.err - 2021-12-06 10:25:06^_^
     * https://openapi.alipaydev.com/gateway.do?alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2016102100732915&biz_content=%7B%22out_trade_no%22%3A%2220210817010101004%22%2C%22total_amount%22%3A0.01%2C%22subject%22%3A%22%E6%B5%8B%E8%AF%95%E5%95%86%E5%93%81%22%2C%22product_code%22%3A%22FAST_INSTANT_TRADE_PAY%22%7D&charset=UTF-8&format=json&method=alipay.trade.page.pay&sign=lp%2B5t23KBZyIsgq9g5DcwEnc%2Fir9MmfswPpIPnAAcv8D4ootk2hmrhvIHb2e9LCsqDkzy8DHPkUayHS7T9%2F9%2BiUU4KAL0jiRu2rBOYv3xhdrqcyOwrBs3P5uSPDRVBLfG6uQr%2BJC9Vct6%2FayTtQOSNYl8q7unur6B7RSnLyn8IXc3hrdgB9CMULX3%2FFO%2FTt%2BAn69N3ZucGRSafKigp5iSXfd%2BqNWu9716znJXoiAn3sf9QX9wwnorfpj9Gc%2BUfut5g2or0W%2FhVWiDX3Q8fRIKAJXsh2I3AVSBer7374VfT5l2MskWqXSmOvF7cu7tYncoBmc9uD%2BT0pK5wuM3B663A%3D%3D&sign_type=RSA2&timestamp=2021-12-06+10%3A25%3A02&version=1.0
     *
     *
     */

}
